/*
 * MenuItemDelegate.h  0.4.0 / Dec 04, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
#ifndef MENUITEMDELEGATE_H
#define MENUITEMDELEGATE_H

#include "Cute4jSwing.h"

#include "ActionComponentDelegate.h"
#include "QLabelAdapter.h"

// MenuItemDelegate Class. -----------------------------------------------------

/*!
 * \brief MenuItem Delegate.
 *
 * \author Slobodan Vrkacevic
 * \version 0.4.0
 */
class CUTE4J_EXPORT MenuItemDelegate : public ActionComponentDelegate
{
  Q_OBJECT
protected:
  MenuItemDelegate(JNIEnv *env, jobject obj);
public slots: // native calls
  void setText(JNIEnv *env, jstring text);
  void setShortcut(JNIEnv *env, jstring shortcut);
  void setIcon(JNIEnv *env, jobject iconSet);
public: // native calls
  static void initialize(JNIEnv *env, jclass cls);
  static jlong newInstance(JNIEnv *env, jobject obj);
public: // native callbacks
  void actionTriggered(jint modifiers);
protected slots:
  void triggeredSlot();
protected:
  inline QLabelAdapter *label() const;
protected:
  virtual QWidget *createQWidget();
  virtual QAction *createQAction();
  virtual void deleteQWidget(QWidget *widget);
  virtual void deleteQAction(QAction *action);
  virtual QWidget *convertToQWidget(QAction *action);
  virtual QAction *convertToQAction(QWidget *widget);
private:
  QShortcut *m_shortcut;
private:
  static jmethodID sm_actionTriggeredMID;
};

// MenuItemDelegate :: Protected Inline Member Function. -----------------------

/*!
 * \brief Returns label data member.
 *
 * \return label data member
 */
inline QLabelAdapter *MenuItemDelegate::label() const
{
  return static_cast<QLabelAdapter *>(widget());
}

// Macro Definitions. ----------------------------------------------------------

#define MENU_ITEM_DELEGATE (reinterpret_cast<MenuItemDelegate *>(delegate))

#endif // MENUITEMDELEGATE_H
